package cn.topkinson.dubbo.filter;
import org.apache.dubbo.common.constants.CommonConstants;
import org.apache.dubbo.common.extension.Activate;
import org.apache.dubbo.rpc.*;
/**
 * @author 黄子濠
 * @date 2020/8/30 22:13
 */
@Activate(group = {CommonConstants.CONSUMER,CommonConstants.PROVIDER})
public class TransportIPFilter  implements Filter {
    @Override
    public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
        long   startTime  = System.currentTimeMillis();
        String remoteAddr = (String)RpcContext.getContext().getAttachment("remoteAddr");
        try {
            // 执行方法
            return  invoker.invoke(invocation);
        } finally {
            //System.out.println("from ["+remoteAddr+"],invoke time:"+(System.currentTimeMillis()-startTime) + "毫秒");
        }
    }
}